<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>File: README.rdoc [rawjsonrpc 0.1.0]</title>

  <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />

  <script src="./js/jquery.js" type="text/javascript"
    charset="utf-8"></script>
  <script src="./js/thickbox-compressed.js" type="text/javascript"
    charset="utf-8"></script>
  <script src="./js/quicksearch.js" type="text/javascript"
    charset="utf-8"></script>
  <script src="./js/darkfish.js" type="text/javascript"
    charset="utf-8"></script>
</head>

<body class="file">
  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="./index.html">Home</a>
          <a href="./index.html#classes">Classes</a>
          <a href="./index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class Index
          <span class="search-toggle"><img src="./images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="./RawJsonRpc.html">RawJsonRpc</a></li>
        
          <li><a href="./RawJsonRpc/ClientSock.html">RawJsonRpc::ClientSock</a></li>
        
          <li><a href="./RawJsonRpc/RawClientJsonRpc.html">RawJsonRpc::RawClientJsonRpc</a></li>
        
          <li><a href="./RawJsonRpc/RawServerJsonRpc.html">RawJsonRpc::RawServerJsonRpc</a></li>
        
          <li><a href="./RawJsonRpc/ServerSocket.html">RawJsonRpc::ServerSocket</a></li>
        
          <li><a href="./RawJsonRpc/TCPServer.html">RawJsonRpc::TCPServer</a></li>
        
          <li><a href="./RpcError.html">RpcError</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    
<h1>rawjsonrpc</h1>

<p>rawjsonrpc is a libary to create a jsonrpc client for every type of stream.
It also profides one client for tcpsocket, an server for one client and on
server based on gserver from the ruby stdlib.  This is libary is a my first
try in ruby to create a gem. Its more a test how  gems work but i hope i
can help somebody with this lib.</p>

<h2>load lib</h2>

<p>install libary</p>

<pre>gem install rawjsonrpc</pre>

<p>include rawjsonrpc in your programm</p>

<pre>require 'rawjsonrpc'</pre>

<h2>Use the TCP client </h2>

<p>Create a client to send rpc calls.</p>

<pre>client = RawJsonRpc::ClientSocket.new('192.168.2.10', 8080) #creates TCP client
ret = client.request(&quot;func1&quot;, nil)                 #calles func1 with no para
                                                   #returns result in ret
ret = client.request(&quot;func2&quot;, 1, 3.0, :test, &quot;om&quot;) #calles func2 with 4 paras
ret = client.func3([1, 2, 3, 4])                   #calles func3 with a array
client.notification(&quot;noti&quot;, 1, &quot;t&quot;)                #send notifaction no 
                                                   # #return value
client.close()</pre>

<h2>Use server TCP simple</h2>

<p>Use the libary to serve functions over tcp ip.</p>

<pre>client = RawJsonRpc::SimpleServerSocket.new(8080)
client.add_method(&quot;func1&quot;, method(&quot;do_stuff1&quot;)) # adds do_stuff1 as &quot;func1&quot;
client.add_method(&quot;foo&quot;, method(:bar))          # adds bar as foo
client.add_block(&quot;func2&quot;){|a,b, *c|              # adds a block with 2 args
  #do stuff                                     # and args as func2
}
client.serve()</pre>

<h2>use gserver TCP</h2>

<p>Lock in the stdlib for usage. The server delivers automaticly the
functions. Beware of adding methods or blocks after starting.</p>

<pre>server = RawJsonRpc::TCPServer.new(#args)</pre>

<h2>implement your own jsonclient</h2>

<p>Boilerplate Code to create your own client.</p>

<pre>class superclient &lt; RawJsonRpc::RawClientJsonRpc 
  def initiailize(*args)
   # init stream
  end

  def send_request(jsonstring)
    #send stream
  end

  def get_response
    #return the response
  end

  def close
    #close resources if needed
  end
end</pre>

<h2>implement your server</h2>

<p>The boilerplattecode to create a new server.</p>

<pre>class superserver
  include RawJsonRpc::RawServerJsonRpc

  def initizial(*args)
    #init
  end

  def serve
    #get data from client
    response = execute(jsonstring) #transfers the string and calls function
                                 #return response string or nil if its a
                                 # #notification
    #send response
  end

  def end
    #stuff
  end 
end</pre>

<h2>known issues</h2>
<ul><li>
<p>Block arguments can’t be checkt because they are blocks not lamdbas</p>
</li></ul>

<h2>Your implementations</h2>

<p>feel free to contribute your client and servers to the project.</p>

<h2>TODO </h2>
<ul><li>
<p>add examples</p>
</li><li>
<p>add doc for gserver implementation</p>
</li><li>
<p>add a piping server and client</p>
</li><li>
<p>fix block argumentchecks</p>
</li></ul>

<h2>Contributing to rawjsonrpc</h2>
<ul><li>
<p>Check out the latest master to make sure the feature hasn’t been
implemented or the bug hasn’t been fixed yet</p>
</li><li>
<p>Check out the issue tracker to make sure someone already hasn’t requested
it and/or contributed it</p>
</li><li>
<p>Fork the project</p>
</li><li>
<p>Start a feature/bugfix branch</p>
</li><li>
<p>Commit and push until you are happy with your contribution</p>
</li><li>
<p>Make sure to add tests for it. This is important so I don’t break it in a
future version unintentionally.</p>
</li><li>
<p>Please try not to mess with the Rakefile, version, or history. If you want
to have your own version, or is otherwise necessary, that is fine, but
please isolate to its own commit so I can cherry-pick around it.</p>
</li></ul>

<h2>Copyright</h2>

<p>Copyright © 2012 Alexander Schrode. See LICENSE.txt for further details.</p>

  </div>

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>
</body>
</html>

